package com.itbaizhan.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChatMemoryConfig {


    @Bean
    public ChatMemory getChatMemory() {
        // 内存中的聊天实列
        return new InMemoryChatMemory();
    }

    @Bean
    public ChatClient getChatClient(ChatModel chatModel,ChatMemory memory) {
        return ChatClient.builder(chatModel)
                // 聊天记忆
                .defaultAdvisors(new MessageChatMemoryAdvisor(memory))
                .build();

    }

}
